package com.lzh.redis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Controller
public class redislink {

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/redisTest")
    public String testRedis(Model model) {
        //设置值到redis
        redisTemplate.opsForValue().set("name","666");
        //从redis获取值
        String name = (String)redisTemplate.opsForValue().get("name");
        model.addAttribute("name",name);
        return "redistest";
    }

}
